
package com.sskj.mq.consumer;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.sskj.jkzx.domain.entity.amap.message.JdywtxMessage;
import com.sskj.jkzx.domain.entity.amap.message.Message;
import com.sskj.jkzx.repository.amap.message.MessageQueryServiceImpl;

@Component
public class JdYwtxjlMQConsumer {

	protected final Log logger = LogFactory.getLog(JdYwtxjlMQConsumer.class);

	@Autowired
	private SimpMessagingTemplate template;

	@Autowired
	private MessageQueryServiceImpl messageService;

	/**
	 * 监督业务提醒消息订阅
	 * 
	 * @param text
	 */
//	@JmsListener(destination = "YWTXJL", containerFactory = "ywtxjlListener")
	public void receiveYwtxjlTopic(String text) {

		logger.info("Topic [监督业务提醒消息]：" + text);
		if (StringUtils.isNotBlank(text)) {
			JSONObject resultJson = JSONObject.parseObject(text);

			Message message = new Message("JD", resultJson.toJSONString());
			messageService.saveMessage(message);

			JdywtxMessage result = new JdywtxMessage();
			result.setClassName(resultJson.getString("className"));
			result.setObjId(resultJson.getString("objId"));
			result.setGlId(resultJson.getString("glId"));
			result.setGlName(resultJson.getString("glName"));
			result.setLongitude(resultJson.getString("longitude"));
			result.setLatitude(resultJson.getString("latitude"));
			result.setTxms(resultJson.getString("txms"));
			result.setMsglx(resultJson.getString("msglx"));
			result.setType("JD");
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			result.setJssj(dateFormat.format(new Date()));

			template.convertAndSend("/topic/jdmessage", result);
		}

	}
}
